package com.usergood;

import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

public class UserGoodBean implements WritableComparable<UserGoodBean> {
    //用户id
    private String userId;
    //商品id
    private String goodId;


    //必须要有空参构造函数
    public UserGoodBean() {
    }

    @Override
    public int compareTo(UserGoodBean comPareBean) {
        int nResult = this.userId.compareTo(comPareBean.getUserId());
        if (nResult == 0) {
            return this.goodId.compareTo(comPareBean.getGoodId());
        } else {
            return nResult;
        }
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getGoodId() {
        return goodId;
    }

    public void setGoodId(String goodId) {
        this.goodId = goodId;
    }

    @Override
    public void write(DataOutput dataOutput) throws IOException {
        dataOutput.writeUTF(userId);
        dataOutput.writeUTF(goodId);
    }

    @Override
    public void readFields(DataInput dataInput) throws IOException {
        userId = dataInput.readUTF();
        goodId = dataInput.readUTF();

    }

    @Override
    public String toString() {
        return userId + "\t" + goodId;
    }
}
